package pir.hillchen.std.mybatis.txmapper.mapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import pir.hillchen.std.mybatis.txmapper.entity.User;

import java.util.List;

/**
 * Created by hillchen on 2017/9/28 0028.
 */
@Repository
public class UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public User findUserById(String userId){
        List<User> users = jdbcTemplate.query("select * from user where id = ?",new Object[]{userId},
                new BeanPropertyRowMapper<User>(User.class));
        if(CollectionUtils.isEmpty(users)){
            return null;
        }else{
            return users.get(0);
        }
    }


}
